#include "rendertarget.h"
#include <QPixmap>
#include <QDebug>
//渲染对象的信息集

RenderTarget::RenderTarget(QString pa, QVector2D po, int l, float s):path(pa),pos(po),layer(l),sizeTimes(s)
{
}

RenderTarget::RenderTarget(const RenderTarget &rt)
{
    this->path = rt.path;
    this->pos = rt.pos;
    this->layer = rt.layer;
    this->sizeTimes = rt.sizeTimes;
    if(rt.size)
    {
        QVector2D* size = new QVector2D(rt.size->x(),rt.size->y());
        this->size = size;
    }
    this->width = rt.width;
    this->height = rt.height;
    //复制纹理
    this->Activate();
}

RenderTarget::~RenderTarget()
{
    delete texture;
    delete size;
}

void RenderTarget::SetWidth(float w)
{
    width = w;
}

void RenderTarget::SetHeight(float h)
{
    height = h;
}

float RenderTarget::GetWidth()
{
    return width;
}

float RenderTarget::GetHeight()
{
    return height;
}

void RenderTarget::SetSize(QSize s)
{
    this->width = s.width();
    this->height = s.height();
}

QVector2D RenderTarget::GetPos()
{
    return pos;
}

void RenderTarget::SetPos(QVector2D p)
{
    pos = p;
}

void RenderTarget::SetLayer(int layer)
{
    this->layer = layer;
}

int RenderTarget::GetLayer()
{
    return layer;
}

QOpenGLTexture *RenderTarget::GetTexture()
{
    return this->texture;
}

QString RenderTarget::GetPath()
{
    return path;
}

void RenderTarget::Activate()
{
    texture = new QOpenGLTexture(QImage(path).mirrored(),QOpenGLTexture::GenerateMipMaps);
    texture->setWrapMode(QOpenGLTexture::Repeat);
    texture->setWrapMode(QOpenGLTexture::DirectionS,QOpenGLTexture::Repeat);
    texture->setWrapMode(QOpenGLTexture::DirectionT,QOpenGLTexture::Repeat);
    texture->setMinificationFilter(QOpenGLTexture::Nearest);
    texture->setMagnificationFilter(QOpenGLTexture::Linear);
    QPixmap pix(path);
    this->width = pix.width();
    this->height = pix.height();
}

